﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace eVoting
{
    public partial class VotingResults : System.Web.UI.Page
    {
        DBManager db;
        int userId = 3;
        int selectedPoll;
        protected void Page_Load(object sender, EventArgs e)
        {
            db = new DBManager();
            if (!IsPostBack)
            {
                List<Poll> polls = db.getUserTerminatedPolls(userId);

                PollsDdl.Items.Add("Select a poll");
                
                for (int i = 0; i < polls.Count; i++)
                {
                    PollsDdl.Items.Add(new ListItem(polls[i].name, polls[i].ID + ""));

                }
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (PollsDdl.SelectedIndex != 0)
            {
                selectedPoll = int.Parse(PollsDdl.SelectedItem.Value);
                ResultTable.Attributes.Add("candidate", "Candidate");
                ResultTable.Attributes.Add("result", "Result in %");
                TableRow row = new TableRow();
                row.Attributes.Add("candidate","Sarah");
                row.Attributes.Add("result", "0%");
                ResultTable.Rows.Add(row);

                ResultTable.DataBind();
                ResultTable.Visible = true;
            }
            

        }
    }
}
